using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using THSLib;using THSERP.BaseProvider;
using DevExpress.XtraGrid.Views.Grid;
using System.Data;using THSERP.BusinessEntities;using THSERP.BaseProvider;
using System.Windows.Forms;

namespace THSERP.Modules.CompanyConstant
{
    public partial class PriceLevelGridControl : THSGridControl
    {
        public override void InitGridControlDataSource()
        {
            base.InitGridControlDataSource();
            ARPriceLevelsController objPriceLevelsController = new ARPriceLevelsController();
            DataSet ds = objPriceLevelsController.GetAllObjects();
            ds.Tables[0].Rows.Remove(ds.Tables[0].Rows[0]);
            this.DataSource = ds.Tables[0];
            this.RefreshDataSource();
        }

        protected override GridView InitializeGridView()
        {
            GridView gridView = base.InitializeGridView();
            foreach (DevExpress.XtraGrid.Columns.GridColumn column in gridView.Columns)
                column.OptionsColumn.AllowEdit = true;
            gridView.OptionsView.NewItemRowPosition = DevExpress.XtraGrid.Views.Grid.NewItemRowPosition.Bottom;
            return gridView;
        }

        protected override void GridView_KeyUp(object sender, KeyEventArgs e)
        {
            base.GridView_KeyUp(sender, e);

            GridView gridView = (GridView)sender;
            if (e.KeyCode == Keys.Delete)
            {
                DataView dataView = (DataView)gridView.DataSource;
                DataRow row = (DataRow)gridView.GetDataRow(gridView.FocusedRowHandle);
                if (row != null)
                    dataView.Table.Rows.Remove(row);
            }
            gridView.RefreshData();
        }
    }
}
